import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @Author 12629
 * @Description：
 */
public class Test {

    public static void main(String[] args) {


        int[][] array = {{1,2,3},{4,5,6}};

        for(int[] tmp : array) {
            for(int x : tmp) {
                System.out.print(x+" ");
            }
            System.out.println();
        }
        System.out.println();

        System.out.println(Arrays.deepToString(array));


        //System.out.println(array[0][1]);
        /*System.out.println(Arrays.toString(array[0]));
        System.out.println(Arrays.toString(array[1]));*/

        /*System.out.println(array[0].length);
        System.out.println(array.length);*/

       /* int[] array22 = {1,2,3};
        System.out.println(array22);*/

        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[i].length; j++) {
                System.out.print(array[i][j]+" ");
            }
            System.out.println();
        }




        int[][] array2 = new int[][]{{1,2,3},{4,5,6}};

        int[][] array3 = new int[2][3];




    }

    /**
     * @param array 数组
     * @param key 找的关键字
     * @return 找到的数据的下标
     */
    public static int binarySearch(int[] array,int key) {
        int left = 0;
        int right = array.length-1;
        while (left <= right) {
            int mid = (left + right) / 2;
            if(array[mid] < key) {
                left = mid+1;
            }else if(array[mid] > key) {
                right = mid-1;
            }else {
                return mid;
            }
        }
        return -1;
    }

    public static void bubbleSort(int[] array) {
        //i 表示 比较的趟数
        for (int i = 0; i < array.length-1; i++) {

            for (int j = 0; j < array.length-1-i; j++) {

                if(array[j] > array[j+1]) {
                    swap(array,j,j+1);
                }
            }
        }
    }

    private static void swap(int[] array,int i,int j) {
        int tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
    }

    public static void reverse(int[] array) {
        int left = 0;
        int right = array.length-1;
        while (left < right) {
            swap(array,left,right);
            left++;
            right--;
        }
    }

    public static void main15(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9};
        reverse(array);
        System.out.println(Arrays.toString(array));
    }


    public static void main14(String[] args) {
        int[] array1 = {1,2,3,4,5,6,7,18,9};
        int[] array2 = {1,2,3,4,5,6,7,18,9,20};

        boolean flg =Arrays.equals(array1,array2);
        System.out.println(flg);


        int[] array3 = new int[10];
        Arrays.fill(array3,3,5,-1);//[3,5)
        System.out.println(Arrays.toString(array3));

    }

    public static void main13(String[] args) {
        int[] array = {1,2,3,4,5,6,7,18,9};
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));

        System.out.println(Arrays.binarySearch(array, 7));

        //System.out.println(binarySearch(array, 9));
    }

    public static void main12(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9};
        int sum = 0;
        for(int x :array) {
            sum += x;
        }
        System.out.println(sum*1.0 / array.length);
    }

    public static int[] copyOf(int[] array) {
        int[] copy = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            copy[i] = array[i];
        }
        return copy;
    }

    public static void main11(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9};
        /**
         * 参数1：是要拷贝的数组
         * 参数2：是要拷贝的长度
         */
        //int[] copy1 = Arrays.copyOf(array,2*array.length);
        int[] copy2 = Arrays.copyOfRange(array,-2,15);//[2,5)


        int[] copy = new int[array.length];

        System.arraycopy(array,0,copy,0,array.length);

        System.out.println(Arrays.toString(copy));

    }

    public static void main10(String[] args) {
        int[] array = {1,2,3,4};
        int[] copy = copyOf(array);
        System.out.println(Arrays.toString(copy));

        int[] array2 = {1,2,3,4};
        int[] array3 = array2;

        System.out.println(Arrays.toString(array3));
    }

    public static String myToString(int[] array) {
        String str = "[";
        for (int i = 0; i < array.length; i++) {
            str = str + array[i];
            if(i != array.length-1) {
                str = str + ", ";
            }
        }
        str = str + "]";
        return str;
    }

    public static void main9(String[] args) {
        int[] array = {1,2,3,4};
        String ret = myToString(array);
        System.out.println(ret);
    }

    public static int[] test() {
        int[] ret = {1,2,3,4};
        return ret;
    }

    public static void main8(String[] args) {
        int[] tmp = test();
        System.out.println(Arrays.toString(tmp));
    }






    public static void func1(int[] array) {
        array = new int[]{1,2,3};
    }
    public static void func2(int [] array) {
        array[0] = 199;
    }
    public static void main7(String[] args) {
        int[] array = {10,20,30};
        func1(array);
        //func2(array);
        System.out.println(Arrays.toString(array));
    }

    public static void print(int[] array) {
        array[0] = 99;
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println();
    }

    public static void main6(String[] args) {
        int[] array = {10,20,30};

        print(array);

        System.out.println("========");
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println();
    }


    public static void main5(String[] args) {
        int[] array1 = new int[3];
        array1[0] = 10;
        array1[1] = 20;
        array1[2] = 30;
        int[] array2 = new int[]{1,2,3,4,5};
        array2[0] = 100;
        array2[1] = 200;
        array1 = array2;
        array1[2] = 300;
        array1[3] = 400;
        array2[4] = 500;
        for (int i = 0; i < array1.length; i++) {
            System.out.print(array1[i]+" ");
        }
        System.out.println("===============");
        for (int i = 0; i < array2.length; i++) {
            System.out.print(array2[i]+" ");
        }

    }
    public static void main4(String[] args) {

        int aa = 10;

        int[] array = {12,23,34,45,56};

        System.out.println(array[0]);

        int[] array2 = null;

        System.out.println(array2.length);

    }
    public static void main3(String[] args) {
        int[] array = {12,23,34,45,56};

        int aa = 10;


        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] +" ");
        }
        System.out.println();

        for (int x : array) {
            System.out.print(x +" ");
        }
        System.out.println();

        //把数组 以字符串的形式进行输出
        String ret = Arrays.toString(array);
        System.out.println(ret);

    }
    public static void main2(String[] args) {
        int[] array = {12,23,34,45,56};
        System.out.println(array[2]);

        array[2] = 134;

        System.out.println(array[2]);

        System.out.println(array.length);

    }
    public static void main1(String[] args) {
        int[] array = {1,2,3,4,5};

        int[] array2 = new int[]{1,2,3,4,5};

        int a = 10;
        int[] array3 = new int[a];

        /*int array2[] = {1,2,3};

        */

        int[] array4;
        array4 = new int[]{1,2,3,4};

       /* int[] array5;
        array5 = {1,2,3,4,5};*/

        boolean[] flgs = new boolean[5];

    }
}
